package com.xiaoxian.system.service.impl;

import com.xiaoxian.basic.service.impl.BaseServiceImpl;
import com.xiaoxian.system.domain.DictionaryDetail;
import com.xiaoxian.system.domain.DictionaryType;
import com.xiaoxian.system.mapper.DictionaryDetailMapper;
import com.xiaoxian.system.mapper.DictionaryTypeMapper;
import com.xiaoxian.system.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DictionaryTypeServiceImpl extends BaseServiceImpl<DictionaryType> implements IDictionaryTypeService {
    @Autowired
    private DictionaryTypeMapper dictionaryTypeMapper;
    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;
    @Transactional
    @Override
    public void delete(Long id) {
        List<DictionaryDetail> all = dictionaryDetailMapper.findAll();
        for (DictionaryDetail dictionaryDetail : all) {
            if(dictionaryDetail.getTypes_id()==id){
                dictionaryDetailMapper.delete(dictionaryDetail.getId());
            }
        }
        dictionaryTypeMapper.delete(id);
    }

    @Transactional
    @Override
    public void patchDelete(List<Long> ids) {
        List<DictionaryDetail> all = dictionaryDetailMapper.findAll();
        for (Long id : ids) {

            for (DictionaryDetail dictionaryDetail : all) {
                if(dictionaryDetail.getTypes_id()==id){
                    dictionaryDetailMapper.delete(dictionaryDetail.getId());
                }
            }
        }
        dictionaryTypeMapper.patchDelete(ids);
    }
}
